package com.test.daily.leetcode.y2022.m07.day0716.v06;

import java.util.LinkedList;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/16 下午 04:17
 * @version: 1.0
 */
public class Solution {
    /**
     * Initialize your data structure here.
     */

    public static class MovingAverage {

        int size;
        int sum;
        LinkedList<Integer> list;
        public MovingAverage(int size) {
            this.size = size;
            list = new LinkedList<>();
            sum = 0;
        }
        public double next(int val) {
            if (list.size() == size) {
                sum -= list.pollFirst();
            }
            list.addLast(val);
            sum += val;
            double ans = (double) sum / list.size();
            System.out.println("ans:" + ans);
            return ans;
        }
    }

    public static void main(String[] args) {
        MovingAverage movingAverage = new MovingAverage(3);
        movingAverage.next(1);
        movingAverage.next(10);
        movingAverage.next(3);
        movingAverage.next(5);
    }

}
